iT邦幫忙

2024 iThome 鐵人賽

DAY 26
0
Modern Web

關於寫react 那二三事系列 第 26

Day26 Primereact的Tabview 以及Tabmenu

  • 分享至 

  • xImage
  •  

今天想說說TabView 以及TabMenu 增加左右箭頭的
TabView有自己的scroll 但是有顯示上的問題
https://ithelp.ithome.com.tw/upload/images/20240827/20168266fnu45qdNyF.jpg

我先把左右箭頭建好,明天再開始魔改調整吧
時間不太夠 Q__Q

import React, { useState, useRef, useEffect } from "react";
import { TabMenu } from 'primereact/tabmenu';
import { MenuItem } from 'primereact/menuitem';
import { TabView, TabPanel } from 'primereact/tabview';

const TabCompnent: React.FC = () => {
  const [activeIndex, setActiveIndex] = useState<number>(0);

  const items: MenuItem[] = [
    { label: 'Dashboard', icon: 'pi pi-home' },
    { label: 'Transactions', icon: 'pi pi-chart-line' },
    { label: 'Products', icon: 'pi pi-list' },
    { label: 'Messages', icon: 'pi pi-inbox' },
    { label: 'Dashboard1', icon: 'pi pi-home' },
    { label: 'Transactions1', icon: 'pi pi-chart-line' },
    { label: 'Products1', icon: 'pi pi-list' },
    { label: 'Messages1', icon: 'pi pi-inbox' }
  ];
  let tabItems = [];
 
  return (
    <div>
      <div className="p-tabmenu-cus">
        <div className="p-leftbtn" onClick={handleMenuLeft} />
        <div ref={menuRef} style={{overflow:'hidden'}}><TabMenu model={items} activeIndex={activeIndex} onTabChange={(e) => setActiveIndex(e.index)} /></div>
        <div className="p-rightbtn" onClick={handleMenuRight}/>
      </div>
      <div className="p-tabview-cus">
        <div className="p-leftbtn" />
        <div ref={viewRef} style={{overflow:'hidden'}}><TabView pt={{ panelContainer: { hidden: true } }}>
          {items.map((tab: MenuItem) => {
            return (
              <TabPanel key={`${tab.label}_`} leftIcon={`${tab.icon} mr-2`} header={tab.label} />
            );
          })}
        </TabView></div>
        <div className="p-rightbtn" />
      </div>
    </div>
  );
}

export default TabCompnent;

css

.p-tabmenu-cus {
  display: flex;
  justify-content: space-between;
  .p-leftbtn {
    &::before {
      font-family: 'primeicons';
      content: "\e931";
      height: 50px;
      line-height: 50px;
    }
    &:hover {
      color: #81c784;
    }
  }
  .p-rightbtn {
    &::before {
      font-family: 'primeicons';
      content: "\e932";
      height: 50px;
      line-height: 50px;
    }
    &:hover {
      color: #81c784;
    }
  }
  .p-tabmenu {
    overflow: auto;
    margin: 0 10px;
  }
}

.p-tabview-cus {
  display: flex;
  justify-content: space-between;

  .p-leftbtn {
    &::before {
      font-family: 'primeicons';
      content: "\e931";
      height: 50px;
      line-height: 50px;
    }

    &:hover {
      color: #81c784;
    }
  }

  .p-rightbtn {
    &::before {
      font-family: 'primeicons';
      content: "\e932";
      height: 50px;
      line-height: 50px;
    }

    &:hover {
      color: #81c784;
    }
  }
  .p-tabview {
    overflow: auto;
    margin: 0 10px;
  }
}

那麼 明天見


上一篇
Day 25 Primereact的Steps
下一篇
Day27 Primereact的Tabview 以及Tabmenu
系列文
關於寫react 那二三事30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言